import { forwardRef } from 'react';

import cs from 'classnames';

import styles from './index.module.scss';
import Space from './space';

export interface TextProps
  extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
  type?: 'primary' | 'success' | 'warning' | 'danger';
  /** 禁用 */
  disabled?: boolean;
}

const Text = forwardRef<HTMLDivElement, TextProps>(
  ({ type = 'primary', className, children, disabled, ...rest }, ref) => {
    return (
      <div
        className={cs(
          styles['text'],
          {
            [styles[`text-${type}`]]: type,
            [styles['disabled']]: disabled
          },
          className
        )}
        ref={ref}
        {...rest}
      >
        {children}
      </div>
    );
  }
) as React.ForwardRefExoticComponent<TextProps> & {
  Space: typeof Space;
};

Text.Space = Space;
export default Text;
